package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbAreasMapper;
import com.bw1806.pojo.TbAreas;
import com.bw1806.pojo.TbAreasExample;
import com.bw1806.sellergoods.service.TbAreasService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbAreasServiceImpl implements TbAreasService {

    @Autowired
    private TbAreasMapper tbAreasMapper;

    @Override
    public List<TbAreas> findAll() {
        return tbAreasMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbAreas> pagelist(TbAreas tbAreas,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbAreasExample example=new TbAreasExample();

        TbAreasExample.Criteria criteria = example.createCriteria();

        if(tbAreas!=null){
            //if(tbAreas.getName()!=null && tbAreas.getName().length()>0){
            //    criteria.andNameLike("%"+tbAreas.getName()+"%");
           // }
        }

        Page<TbAreas> page= (Page<TbAreas>) tbAreasMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbAreas tbAreas) {
        Long id = tbAreas.getId();
        if(id != null && id !=0){
            tbAreasMapper.updateByPrimaryKey(tbAreas);
        } else{
            tbAreasMapper.insert(tbAreas);
        }
    }

    @Override
    public TbAreas getById(Long id) {
        return tbAreasMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbAreasMapper.deleteByPrimaryKey(id);
        }
        //tbAreasMapper.deletebth(ids);
    }
}
